#!/bin/bash

echo "=========================================="
echo "测试 Elasticsearch 自动补全 API"
echo "=========================================="

BASE_URL="http://localhost:8080/api/autocomplete"

# 测试健康检查
echo "1. 测试健康检查..."
curl -s "$BASE_URL/health" | jq .
echo ""

# 测试商品自动补全
echo "2. 测试商品自动补全 (iPhone)..."
curl -s -X POST "$BASE_URL/products" \
  -H "Content-Type: application/json" \
  -d '{
    "keyword": "iPhone",
    "indexType": "product",
    "size": 5,
    "highlight": true
  }' | jq .
echo ""

# 测试城市自动补全
echo "3. 测试城市自动补全 (北京)..."
curl -s -X POST "$BASE_URL/cities" \
  -H "Content-Type: application/json" \
  -d '{
    "keyword": "北京",
    "indexType": "city",
    "size": 5,
    "highlight": true
  }' | jq .
echo ""

# 测试用户自动补全
echo "4. 测试用户自动补全 (张三)..."
curl -s -X POST "$BASE_URL/users" \
  -H "Content-Type: application/json" \
  -d '{
    "keyword": "张三",
    "indexType": "user",
    "size": 5,
    "highlight": true
  }' | jq .
echo ""

echo "=========================================="
echo "测试完成"
echo "=========================================="
